package co.yixiang.hw.service.impl;

import co.yixiang.hw.domain.YxSystemFuncShield;
import co.yixiang.utils.ValidationUtil;
import co.yixiang.utils.FileUtil;
import co.yixiang.hw.repository.YxSystemFuncShieldRepository;
import co.yixiang.hw.service.YxSystemFuncShieldService;
import co.yixiang.hw.service.dto.YxSystemFuncShieldDto;
import co.yixiang.hw.service.dto.YxSystemFuncShieldQueryCriteria;
import co.yixiang.hw.service.mapper.YxSystemFuncShieldMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
// 默认不使用缓存
//import org.springframework.cache.annotation.CacheConfig;
//import org.springframework.cache.annotation.CacheEvict;
//import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import co.yixiang.utils.PageUtil;
import co.yixiang.utils.QueryHelp;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import javax.annotation.Resource;


/**
* @author Walert
* @date 2020-02-25
*/
@Service
//@CacheConfig(cacheNames = "yxSystemFuncShield")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class YxSystemFuncShieldServiceImpl implements YxSystemFuncShieldService {

    @Resource
    private YxSystemFuncShieldRepository yxSystemFuncShieldRepository;
    @Resource
    private YxSystemFuncShieldMapper yxSystemFuncShieldMapper;


    @Override
    public YxSystemFuncShieldDto findByVersionNum(String version) {

        YxSystemFuncShield result = new YxSystemFuncShield();
        List<YxSystemFuncShield> list = yxSystemFuncShieldRepository.findByVersionNumAndIsDel(version, 0);
        if(list != null && list.size() > 0){
            result = list.get(0);
        }else{
            Long addTime = System.currentTimeMillis()/1000L;
            result.setCreateTime(addTime);
            result.setVersionNum(version);
            result.setIsShow(0);
            result.setIsDel(0);
            result = yxSystemFuncShieldRepository.save(result);
        }
        return yxSystemFuncShieldMapper.toDto(result);
    }
}